<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>角色管理</title>
    <link rel="shortcut icon" href="favicon.ico">
     <link href="<%=path%>/hplus/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="<%=path%>/hplus/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/iCheck/custom.css" rel="stylesheet"> 
    <link href="<%=path%>/hplus/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/animate.min.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.css">
    <link href="${pageContext.request.contextPath}/hplus/css/plugins/zTree/zTreeStyle/metro.css" rel="stylesheet">
    
    <style> 
        .radio label{
            padding-left: 0;
        }

        .date{
            margin: -8px 20px 0 0;
        }

        .clockpicker{
            margin-top: -8px;
        }

        .i-checks label{
            float: left;
            margin-right: 10px;
        }

        .col-sm-offset-1{
            margin-top: 20px;
        }

        .tishi{
            margin-top: 7px;
            display: inline-block;
        }

        .alert{
            position:absolute;
            top: -15px;
            left: 8%;
            display:none;
        }
        .text-center{
            width:50%;
            margin: 10px 0 20px;
        }

        .radio label::before,.checkbox label::before {
            display: none;
        }
        .form-horizontal .radio{
            display: inline-block;
        }
        .aaa{
            position: absolute; top: 0%; left: 0%; display: block; width: 100%; height: 100%; margin: 0px; padding: 0px; background: rgb(255, 255, 255); border: 0px; opacity: 0;
        }
        .s_line{
            height: 16px;
            line-height: 16px;
            width: 1px;
            float: left;
            margin: 8px 20px;
            background: #666;
        }
        .red{
            color: red;
            margin-right: 5px;
        }
        
        .ztree li a.curSelectedNode{
		background-color:#BEEBFF;
		}
		
		.ztree li span.button.noline_close{background-position: -126px -84px;}									
	    .ztree li span.button.noline_open{background-position: -105px -84px;}
	
    </style>
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content">
        <div class="ibox-content">
            <form method="get" class="form-horizontal">
            
                <div class="form-group">
                    <label class="col-sm-2 control-label"></span>手机号</label>
                    <div class="col-sm-3">
                        <input id="userAccount" type="text" disabled = "disabled" class="form-control" placeholder="员工手机号将作为登录账号" >
                    </div>
                </div>
                
                <div class="form-group">
                    <label class="col-sm-2 control-label">员工姓名</label>
                    <div class="col-sm-3">
                        <input id="userName" type="text" class="form-control" placeholder="请勿超过十个字" >
                    </div>
                </div>                

                <div class="form-group">
                    <label class="col-sm-2 control-label">邮箱</label>
                    <div class="col-sm-3">
                        <input id="userEmail" type="text" class="form-control" placeholder="" >
                    </div>
                </div>
                
                <div class="form-group">
                    <label class="col-sm-2 control-label">员工编码</label>
                    <div class="col-sm-3">
                        <input id="userNumber" type="text" class="form-control" placeholder="" >
                    </div>
                </div>
                
                <div class="form-group">
                    <label class="col-sm-2 control-label">员工密码</label>
                    <div class="col-sm-3" style="color:#03A9F4;line-height: 35px;text-align: left;">
                        <span style="cursor:pointer;" onclick="resetPassword();">重置密码</span>
                    </div>
                </div>
                
                <div class="form-group">
                    <label class="col-sm-2 control-label"><span class="red" style="margin-right:2px">*</span>所在部门</label>
                    <div class="col-sm-3">
                        <button  class="btn btn-primary btn-outline" type="button" data-toggle="modal" href="#" data-target="#myModa4" >选择</button>
                    </div>
                </div>
                
                <div class="form-group">
                    <label class="col-sm-2 control-label">配置角色</label>
                    <div class="col-sm-3">
                    <button  class="btn btn-primary btn-outline" type="button" data-toggle="modal" href="<%=path%>/view/ui/selectRoleForCreateUser" data-target="#role_modal" >选择</button>
                    <i class="fa fa-question-circle" style="cursor:point" data-toggle="tooltip" data-placement="right" title="" data-original-title="用于控制账号登录后可看到的导航、功能模块、数据类型与可操作按钮，选择多个角色，权限可叠加使用"></i>
                    </div>
                </div>
                
                <div class="form-group">
                    <label class="col-sm-2 control-label"></label>
                    <div class="col-sm-10" id="roleSelectDiv">
                    
<!-- 				<div style="padding:5px;color:#FFFFFF;background-color:#B8C9E8;display:inline-block;width: auto;height:auto;border-radius:5px 5px 5px 5px;">
					超级管理员
					<a class="close-link"><i style="color:#FFFFFF;" class="fa fa-times"></i></a>
					</div> -->
					
                    </div>
                    
                </div>
                			
                <div class="form-group">
                    <label class="col-sm-2 control-label"><span class="red" style="margin-right:2px">*</span>数据权限</label>
                    <div class="col-sm-3">
                    <button  class="btn btn-primary btn-outline" type="button" data-toggle="modal" href="#" data-target="#myModa3" >选择</button>
                    <i class="fa fa-question-circle" style="cursor:point" data-toggle="tooltip" data-placement="right" title="" data-original-title="用于控制账号登录后可看到的数据，个人权限仅可看到自己产生的数据，部门权限可看到所选部门全部数据"></i>
                    </div>
                </div>
                
				<!-- 数据权限展示模块 -->
                <div class="form-group">
                    <label class="col-sm-2 control-label">负责门店</label>
                    <div class="col-sm-6">  
                       <div class="col-sm-7">  
                    	<div id="respStore">                    
<!-- 	                      <label class="checkbox-inline i-checks" >
	                           <div class="icheckbox_square-green" style="position: relative;">			
	                               <input  id="storeDataAuth" type="checkbox" checked="checked" value="option1" style="position: absolute; opacity: 0;">
	                               <ins class="iCheck-helper" style="position: absolute; top: 0%; left: 0%; display: block; width: 100%; height: 100%; margin: 0px; padding: 0px; background: rgb(255, 255, 255); border: 0px; opacity: 0;"></ins>
	                            </div> 门店数据
	                      </label> -->
 			
	                     </div>
	                     </div>
	                    <div class="col-sm-5" style="text-align:left;">
	                    <div style="height:10px;"></div>
	                    <i class="fa fa-question-circle" style="cursor:point" data-toggle="tooltip" data-placement="right" title="" data-original-title="用于控制员工可看到哪些门店的数据，如店员不需要看到全部门店会员，可不勾选" ></i>
	                    </div>  
	                 </div> 
                </div>
                
                
                <div class="form-group">
                    <label class="col-sm-2 control-label">归属门店</label>
                    <div class="col-sm-3">
                             <select class="form-control" id="blongStore">
                             </select>
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-sm-2 col-sm-offset-1">
                        <button type="button" class="btn btn-white" data-dismiss="modal" onclick="javascript:window.location.href='<%=path%>/view/ui/organizational';">取消</button>
                        <button onclick="javascript:save();" type="button" class="btn btn-primary" style="margin-left:20px;">确定</button>
                    </div>      
                </div>          
            </form>
        </div>    
    </div>

	<!-- 数据权限配置 -->
    <div hidden="" class="modal inmodal fade" id="myModa3" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-sm">
            <div class="modal-content"  style="width:500px;">
                <div class="modal-header" style="padding: 15px 15px 10px;">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="text-left">数据权限配置</h4>
                </div>
                <div class="text-center" style="width:100%;height:60px;">     
                <!-- CRM角色 -->
                <div class="form-group">
                    <label class="col-sm-4 control-label">请选择数据权限</label>
                    <div class="col-sm-8">
                    
                        <div class="radio i-checks">
                            <label><input id = "peopleAuth" type="radio" checked="" value="option1" name="crm"> <i></i> 个人权限</label>
                        </div>
                        
                        <div class="radio i-checks">
                            <label><input id = "departmentAuth" type="radio" value="option2" name="crm"> <i></i> 部门权限</label>
                        </div>
                        
	                     <label class="checkbox-inline i-checks" style="margin:5 15px 0 0">
	                           <div class="icheckbox_square-green" style="position: relative;">			
	                               <input  id="noBodyAuth" type="checkbox"  value="option1" style="position: absolute; opacity: 0;">
	                               <ins class="iCheck-helper" style="position: absolute; top: 0%; left: 0%; display: block; width: 100%; height: 100%; margin: 0px; padding: 0px; background: rgb(255, 255, 255); border: 0px; opacity: 0;"></ins>
	                            </div> 无归属数据
	                     </label>
                    </div>
                    <div style="height:30px;"></div>
                    <div class="col-sm-12">		
                    <label class="col-sm-5 control-label"></label>	
                    <div id="departmentShow" style="position:absolute;width:330px;height:250px;left:160;top:0;opacity:0.1;background-color:black;z-index: 9999;"></div>		
                    <div class="col-sm-7" style="height:250px;overflow-x:auto;"">
                      <!-- 引入zTree -->		
                      <ul id="treeData" class="ztree" ></ul>  
                     </div>
                     <input id="belognDepartmentId" style="display:none;"></input>
                     <input id="belognDepartmentIdFirst" style="display:none;"></input>
                    </div>								
                 </div>			
                 </div>					
                 <div class="modal-footer" style="text-align:center;border-top:none;">
                     <button type="button" class="btn btn-outline btn-primary" onclick="cancelDataAuth();">取消</button>
                     <button type="button" class="btn btn-primary k_verify" data-dismiss="modal">确定</button>
                 </div>
             </div>
        </div>
    </div> 


	<!-- 所在部门选择 -->
    <div hidden="" class="modal inmodal fade" id="myModa4" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-sm">
            <div class="modal-content"  style="width:400px;">
                <div class="modal-header" style="padding: 15px 15px 10px;">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="text-left">用户部门配置</h4>
                </div>
                <div class="text-center" style="width:100%;height:60px;">     
                <!-- CRM角色 -->
                <div class="form-group">
                    <label class="col-sm-3 control-label">请选择部门</label>
                    <div style="overflow-x:auto;height:250px;" class="col-sm-9">
                      <!-- 引入zTree -->		
                      <ul id="tree" class="ztree" ></ul>  
                    </div>
                </div>

                </div>
                 <div class="modal-footer" style="text-align:center;border-top:none;">
                     <button type="button" class="btn btn-outline btn-primary" onclick="cancel();">取消</button>
                     <button type="button" class="btn btn-primary k_verify" data-dismiss="modal">确定</button>
                 </div>
             </div>
        </div>
    </div> 

    <!-- 选择角色弹框 -->
    <div  class="modal inmodal fade" id="role_modal" tabindex="-1" role="dialog"  aria-hidden="true" >
        <div class="modal-dialog modal-lg">
            <div class="modal-content" >
               
            </div>				
        </div>
    </div>


    <script src="<%=path%>/hplus/js/jquery.min.js?v=2.1.4"></script>
    <script src="<%=path%>/hplus/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="<%=path%>/hplus/js/content.min.js?v=1.0.0"></script>
    <script src="<%=path%>/hplus/js/plugins/chosen/chosen.jquery.js"></script>
    <script src="<%=path%>/hplus/js/plugins/jsKnob/jquery.knob.js"></script>
    <script src="<%=path%>/hplus/js/plugins/jasny/jasny-bootstrap.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/datapicker/bootstrap-datepicker.js"></script>
    <script src="<%=path%>/hplus/js/plugins/prettyfile/bootstrap-prettyfile.js"></script>    
    <script src="<%=path%>/hplus/js/plugins/switchery/switchery.js"></script>
    <script src="<%=path%>/hplus/js/plugins/ionRangeSlider/ion.rangeSlider.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/iCheck/icheck.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/metisMenu/jquery.metisMenu.js"></script>
    <script src="<%=path%>/hplus/js/plugins/colorpicker/bootstrap-colorpicker.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/clockpicker/clockpicker.js"></script>    
    <script src="<%=path%>/hplus/js/plugins/cropper/cropper.min.js"></script>
    <script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
    <script src="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.js"></script>
	<script type="text/javascript" src="<%=path%>/js/marketing/dialog.js"></script>
	<script type="text/javascript" src="<%=path%>/js/marketing/public.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
	<script src="<%=path%>/hplus/js/plugins/zTree/jquery.ztree.all-3.5.min.js"></script>
    <script type="text/javascript">

					
    </script>
    
    <script>
	
       //ajax全局同步、此处功能不需要异步
	   $.ajaxSetup({  
	       async : false  
	   });    
    
       //初始化icheck控件
	   $(document).ready(function(){$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",})});
	
        <!-- 页面自加载方法 -->
        $(function(){
            //初始化用户部门树，数据权限树
        	 initZtree();
            
            //初始化企业下的全部门店
             initStore();
            
        	 //初始化提示框控件
        	 $("[data-toggle='tooltip']").tooltip();
        	 
        	 //部门、个人按钮初始化
        	 checkRadioInit();
         	 
         	 //初始化用户数据，用于回显
         	 initUserData();

        });
        
		
        //初始化用户数据，用于回显
        function initUserData(){
			var url="<%=path%>/account/ajaxSeleUserInfoForUpdate";
	         $.post(url, {
	        	 	"id":getQueryString("userId"), //用户id
		        }, function(data) {
		        	var realData = data.data;
		        	if (data.status == 200) {
		   	 		 //用户名称
		   			 $("#userName").val(realData.name);
		   			 //用户手机号
		   			 $("#userAccount").val(realData.account);
		   			 //用户email	
		   			 $("#userEmail").val(realData.email);
		   			 //员工编号
		   			 $("#userNumber").val(realData.jobNumber);
		        		
		        	 var baseTreeSelect = getQueryString("baseTreeSelect");
					 //设置树的选中状态
					 setTreeNoteSelect("tree",realData.departmentId);
					 $("#belognDepartmentId").val(realData.departmentId);
					 $("#belognDepartmentIdFirst").val(realData.departmentId);

					 //角色权限回显
					 rolesDivTab(realData.roleIds);
					  //个人
					  if(realData.userIdentity == 1){
						//peopleAuth == true && departmentAuth == false && noBodyAuth == false
					      $('#peopleAuth').iCheck('check'); 
						  $('#departmentAuth').iCheck('uncheck'); 
						  $('#noBodyAuth').iCheck('uncheck'); 
						  $("#departmentShow").show();
					  }
					  //部门 
					  if(realData.userIdentity == 2){
						 //peopleAuth == false && departmentAuth == true && noBodyAuth == false
					      $('#peopleAuth').iCheck('uncheck'); 
						  $('#departmentAuth').iCheck('check'); 
						  $('#noBodyAuth').iCheck('uncheck'); 
						  $("#departmentShow").hide();
					  }
				      //个人及无归属
					  if(realData.userIdentity == 3){
						 //peopleAuth == true && departmentAuth == false && noBodyAuth == true
					      $('#peopleAuth').iCheck('check'); 
						  $('#departmentAuth').iCheck('uncheck'); 
						  $('#noBodyAuth').iCheck('check'); 
						  $("#departmentShow").show();
					  }
					  //部门及无归属
					  if(realData.userIdentity == 4){
							//peopleAuth == false && departmentAuth == true && noBodyAuth == true
					      $('#peopleAuth').iCheck('uncheck'); 
						  $('#departmentAuth').iCheck('check'); 
						  $('#noBodyAuth').iCheck('check'); 
						  $("#departmentShow").hide();
					  }
					  
					  if(realData.userIdentity != 1 && realData.userIdentity != 3){
				      var zTree = $.fn.zTree.getZTreeObj("treeData");
					  //数据权限树的回显，一组的负责部门
					  var realDataArr = realData.responsibleDepartmentIds.split(",");
					  //如果为空字符串长度也为1，这里要做非空判断
					  if(realDataArr != ""){
					  for(var i=0;i<realDataArr.length;i++){
						  var node = zTree.getNodeByParam("id",realDataArr[i]);
					      zTree.checkNode(node, true, true);
					  }		
					  }
					  }
					  
					  var storesArr = realData.responsibleStoreIds.split(",");
					  //负责门店数据回显
					  for(var i=0;i<storesArr.length;i++){
						  $("#s"+storesArr[i]).iCheck('check'); 
					  }	
					  //选中select
					  var opts = document.getElementById("blongStore");  
				        var value = realData.storeId;//这个值就是你获取的值;
				            if(value!=""){ 
				            for(var i=0;i<opts.options.length;i++){  
				            if(value==opts.options[i].value){    
				            opts.options[i].selected = 'selected';   
				            break;            
				         }     
					  }}
		        	}
		    	}); 
        }
        
        //回显角色的div标签
        function rolesDivTab(roleIds){
           $("#roleSelectDiv").html('');
           var idsList = roleIds.split(",");
           var idsListName =  [];
   		   var url="<%=path%>/role/ajaxRoleList";
            $.post(url, {
   	    	 }, function(data) {
   	    		var realData = data.data;
   	    		if (data.status == 200) {
   	    			for(var o=0;o<idsList.length;o++){
   	    			for(var i=0;i<realData.length;i++){
   	    					if(realData[i].id == idsList[o]){
   	    						idsListName.push(realData[i].name);
   	    						continue;
   	    				}
   	    			}
   	    			}
   	    		}
   	    	}); 
            
     		var html = "";
    		for(var i=0;i<idsListName.length;i++){
    			html += '<div id=rediv'+idsList[i]+' style="padding:5px;margin-left:5px;color:#FFFFFF;background-color:#B8C9E8;display:inline-block;width: auto;height:auto;border-radius:5px 5px 5px 5px;">';
    			html += "<span>"+idsListName[i]+"</span>"
    			html += "<a class='close-link' onclick='deleteRoleDiv(\""+idsList[i]+"\")'><i style='color:#FFFFFF;' class='fa fa-times'></i></a>";
    			html += '</div>';
    		}
    		$("#roleSelectDiv").html(html); 
        }
        
        
		//初始化部门基础树
		function initZtree(){
        	//保存所有的部门节点数据
        	var zNodes =[];
			//发送ajax请求，从DB中查询该企业下，包含层级关系的全部部门
	      	var url="<%=path%>/department/ajaxSelectAllDepartment";
        	$.post(url, {
    		}, function(data) {
    			var realData = data.data;
    			if (data.status == 200) {
    				for(var i=0;i<realData.length;i++){
    					var treeData = null;
    					//机构团队用不同的图标
    					if(realData[i].companyType == 1){
    					   treeData = {id:realData[i].id,companyType:realData[i].companyType,leaderName:realData[i].leaderName,pId:realData[i].parentDeptId, name:realData[i].name,title:realData[i].title,open:true,icon:"${pageContext.request.contextPath}/images/system/mechanismIcon.png"};
    					}else{
    					   treeData = {id:realData[i].id,companyType:realData[i].companyType,leaderName:realData[i].leaderName,pId:realData[i].parentDeptId, name:realData[i].name,title:realData[i].title,open:true,icon:"${pageContext.request.contextPath}/images/system/teamIcon.png"};
    					}
    					zNodes.push(treeData);
    				}
    				zTree(zNodes);
    				ztreeData(zNodes);
    			}else{		
	        		errorDialog(data.message);
	        	}
    		}); 
		}
		
		
		
	       /*
	       chkboxType: { “Y”: “ps”, “N”: “ps” } 
		   Y 属性定义 checkbox 被勾选后的情况； 
		   N 属性定义 checkbox 取消勾选后的情况； 
		   “p” 表示操作会影响父级节点； 
		   “s” 表示操作会影响子级节点。 
		   */
	       //控件初始化部门基础树
	       function zTree(treeData){
	           var zTree;
	           //用于保存用户选中的节点
	           var curNode;
	           //树属性的定义  
	           var setting = {  
	               check: { 
	            	   enable: false,				
	            	   chkStyle: "checkbox",   //勾选框类型(checkbox 或 radio）
	            	   chkboxType: { "Y": "", "N": "" }   //勾选 checkbox 对于父子节点的关联关系
	               },	
	               //页面上的显示效果  
	               view: {
	                   showLine: false,					
	                   selectedMulti: false
	               }, 
	               data: {
	                   simpleData: {
	                       enable:true,
	                       idKey: "id",
	                       pIdKey: "pId",
	                       rootPId: ""
	                   },  
		               key: {  
		                   title: "title"  
		               } 
	               },
	               callback: {
	                   beforeClick: getCurrentNode,
	                   onClick : zTreeOnClick
	               }
	           };
	           
	           function getCurrentNode(treeId, treeNode) {
	               curNode = treeNode;    
	           }
	           
	           //点击左侧的菜单树，动态展示右侧
	           function zTreeOnClick(){			
	        	   $("#belognDepartmentId").val(curNode.id);
	           	}

	           //初始化树
	           var t = $("#tree");
	           t = $.fn.zTree.init(t, setting, treeData);
	       }
		   
	       /*
	       chkboxType: { “Y”: “ps”, “N”: “ps” } 
		   Y 属性定义 checkbox 被勾选后的情况； 
		   N 属性定义 checkbox 取消勾选后的情况； 
		   “p” 表示操作会影响父级节点； 
		   “s” 表示操作会影响子级节点。 
		   */
	       //数据权限部门树
		   function ztreeData(treeData){
	           var zTree;
	           //用于保存用户选中的节点
	           var curNode;
	           //树属性的定义  
	           var setting = {  
	               check: { 
	            	   enable: true,				
	            	   chkStyle: "checkbox",   //勾选框类型(checkbox 或 radio）
	            	   chkboxType: { "Y": "s", "N": "s" }   //勾选 checkbox 对于父子节点的关联关系
	               },	
	               //页面上的显示效果  
	               view: {
	                   showLine: false,					
	                   selectedMulti: false
	               }, 
	               data: {
	                   simpleData: {
	                       enable:true,
	                       idKey: "id",
	                       pIdKey: "pId",
	                       rootPId: ""
	                   },  
		               key: {  
		                   title: "title"  
		               } 
	               },
	               callback: {
	                   beforeClick: getCurrentNode,
	                   onClick : zTreeOnClick
	               }
	           };
	           
	           function getCurrentNode(treeId, treeNode) {
	               curNode = treeNode;    
	           }
	           
	           //点击左侧的菜单树，动态展示右侧
	           function zTreeOnClick(){			
	           	}

	           //初始化树
	           var t = $("#treeData");
	           t = $.fn.zTree.init(t, setting, treeData);  
		   }
	       
        
	       //设置某节点的选中状态
	       function setTreeNoteSelect(treeName,id){
	        	//根据id获取树的某个节点：
	        	var zTree = $.fn.zTree.getZTreeObj(treeName);
	        	var node = zTree.getNodeByParam("id",id);
	        	//设置node节点选中状态：
	        	zTree.selectNode(node);
	       }
	       
	       //用户选中了所在部门的取消
	       function cancel(){
	        	var baseTreeSelect = $("#belognDepartmentIdFirst").val();
				//设置树的选中状态
				setTreeNoteSelect("tree",baseTreeSelect);
				$("#myModa4").modal("hide");
	       }
        
	       //删除角色div选项卡
	       function deleteRoleDiv(id){
	    	   $("#rediv"+id).remove();
	       }        
	       
	       //数据权限用户选中了取消
	       function cancelDataAuth(){
				$("#departmentShow").show();
	      		$('#peopleAuth').iCheck('check');
	    		$('#departmentAuth').iCheck('uncheck');
	    		$("#myModa3").modal("hide");
	       }
	       
	       //初始化企业下的全部门店
	       function initStore(){
				//部门信息编辑
				 var url="<%=path%>/store/ajaxSelectAllStore";
		         $.post(url, {
			    	 }, function(data) {
			    		var realData = data.data;
			    		if (data.status == 200) {
			    			$("#respStore").html('');
			    			var html = "";
			    			for(var i=0;i<realData.length;i++){
			    				//为门店下拉框赋值
			        	    	if(i == 0){
			            	    	$("<option  value='"+realData[i].id+"' selected>"+realData[i].name+"</option>").appendTo("#blongStore");
			            	    	}else{
			            	    	$("<option  value='"+realData[i].id+"'>"+realData[i].name+"</option>").appendTo("#blongStore");
			            	   	}
			    				//为门店多选框赋值
			    				html += '<label class="checkbox-inline i-checks" >';
			        	    	html += '<div class="icheckbox_square-green" style="position: relative;">';
		                        html += '<input id="s'+realData[i].id+'"  name="s'+realData[i].id+'" type="checkbox" value="option1" style="position: absolute; opacity: 0;">';   	
		                        html += '<ins class="iCheck-helper" style="position: absolute; top: 0%; left: 0%; display: block; width: 100%; height: 100%; margin: 0px; padding: 0px; background: rgb(255, 255, 255); border: 0px; opacity: 0;"></ins>';      
		                        html += '</div>'+realData[i].name;       
		                        html += '</label>';  
			    			}
			    			$("#respStore").html(html);
			            	//初始化iCheck控件,该控件一定要最后初始化，为的是在页面所有icheck都生成完毕后初始化
			            	initICheck();
			    		}
			    	}); 
	       }
	       
			//初始化icheck控件
			function initICheck(){
				$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",})
			}
			
			//将用户信息入库
			function save(){
		    //手机号验证规则
		    var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
	        //邮箱验证规则
	        var myregEmail = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
		    //整数验证规则
	        var myRegZx = /^[0-9]*[1-9][0-9]*$/;
		    
		    
			if($("#userAccount").val() == ''){
			   errorDialog("手机号不能为空");
			   return;
			}
			
        	if(!myreg.test($("#userAccount").val())) { 
        		errorDialog("请填写正确手机号");
        	    return; 
        	}    
				
			
			if($("#userName").length > 10){
				   errorDialog("员工姓名请勿超过10个字");
				   return;
			}
			
			if($("#userEmail").val() != null && $("#userEmail").val() != ''){
				if(!myregEmail.test($("#userEmail").val())){
	        		errorDialog("请填写正确邮箱");
	        	    return; 
				}
			}
				
			if($("#userNumber").val() != null && $("#userNumber").val() != ''){
				if(!myRegZx.test($("#userNumber").val())){
					errorDialog("请填写正确员工编号");
					return;
				}
			}
				
			var roles = "";
			$("div[id^='rediv']").each(function(){//each()方法遍历所有的复选框 
				var roleid = $(this).attr("id");
				roles += roleid.substring(5,roleid.length) + ",";
			}) 
			if(roles != ""){				
				roles = roles.substring(0,roles.length - 1);
			}
			
			//if(roles == ''){
			//	errorDialog("请选择角色");
			//	return;
			//}
				

	 		 //用户名称
			 var userName = $("#userName").val();
			 //用户手机号
			 var userAccount = $("#userAccount").val();
			 //用户email	
			 var userEmail = $("#userEmail").val();
			 //员工编号
			 var userNumber = $("#userNumber").val();
			 //所属部门
			 var belognDepartmentId = $("#belognDepartmentId").val(); 
			 
			 	var userIdentity = 0;
				//个人选中状态
				var peopleAuth = $('#peopleAuth').is(':checked');
				//部门选中状态
				var departmentAuth = $('#departmentAuth').is(':checked');
				//无归属选中状态
				var noBodyAuth = $('#noBodyAuth').is(':checked');
				//个人
				if(peopleAuth == true && departmentAuth == false && noBodyAuth == false){
					userIdentity = 1;
				}
				//部门 
				if(peopleAuth == false && departmentAuth == true && noBodyAuth == false){
					userIdentity = 2;
				}
				//个人及无归属
				if(peopleAuth == true && departmentAuth == false && noBodyAuth == true){
					userIdentity = 3;
				}
				//部门及无归属
				if(peopleAuth == false && departmentAuth == true && noBodyAuth == true){
					userIdentity = 4;
				}
	        	//用户选择的模块权限
	        	var treeObj = $.fn.zTree.getZTreeObj("treeData");
	            nodes=treeObj.getCheckedNodes(true);
	        	//拿到一组负责部门权限
	        	var fzdepartment = "";
	            for(var i=0;i<nodes.length;i++){  
	            	if(i == 0){
	            		fzdepartment += nodes[i].id; //获取选中节点的值  
	            	}else{
	            		fzdepartment += "," + nodes[i].id; //获取选中节点的值  
	            	}
	            }  
	            
				var stores = "";
			    $("input[name^='s']").each(function(){//each()方法遍历所有的复选框 
			        if($(this).is(':checked') == true){//这里就可以判断当前是否被选择了 
			        	var value = $(this).attr("name");
			        	stores += value.substring(1,value.length) + ",";
			        }
			    }) 
				 if(stores != ""){				
					 stores = stores.substring(0,stores.length - 1);
				 }
			    
			    //归属门店
			    var blongStore = $("#blongStore option:selected").val();
				var url="<%=path%>/account/ajaxUpdateUser";
		         $.post(url, {
		        	 	"id":getQueryString("userId"),
		        	 	"responsibleStoreIds":stores, //用户负责的一组门店
			        	"storeId":blongStore,  //用户所属门店
			        	"responsibleDepartmentIds":fzdepartment, //用户负责的一组部门
			        	"departmentId":belognDepartmentId, //用户所属部门
			        	"userIdentity":userIdentity, //用户身份标识
			        	"roleIds":roles, //用户对应的一组角色
			        	"name":userName, //用户名
			        	"account":userAccount, //手机号
			        	"email":userEmail, //邮箱
			        	"jobNumber":userNumber //员工编号
			    	 }, function(data) {
			    		var realData = data.data;
			    		if (data.status == 200) {
                            var url = '<%=path%>/view/ui/organizational';
                            SuccessDialogByUrl("员工编辑成功!","",url);
                            setTimeout(function () { window.location.href=url; }, 1600);

			    		}else{		
				        	errorDialog(data.message);
				        }
			    	}); 
			    
			    //alert(stores+"---"+blongStore+"---"+fzdepartment+"---"+userIdentity +"---" + roles +"---"+ userName+"---"+userAccount+"---"+userEmail+"---"+userNumber+"---"+belognDepartmentId);
		}
			
			
			//重置密码
			function resetPassword(){
				var url="<%=path%>/account/ajaxResetPassword";
		         $.post(url, {
		        	 	"id":getQueryString("userId"), //用户id
			        }, function(data) {
			        	if (data.status == 200) {
			        	successDialog("重置密码成功","密码将以短信的形式通知");
			        	}
			    	});
			}
			
			
			//部门、个人单选按钮初始化
			function checkRadioInit(){
				
	        	 //个人被选中
	        	 $('#peopleAuth').on('ifChecked', function(event){ //ifCreated 事件应该在插件初始化之前绑定 
					$("#departmentShow").show();
		      		$('#peopleAuth').iCheck('check');
		    		$('#departmentAuth').iCheck('uncheck');
	        	 }); 		
	        	  
	        	 //部门被选中
	        	 $('#departmentAuth').on('ifChecked', function(event){ //ifCreated 事件应该在插件初始化之前绑定 
	        		$("#departmentShow").hide();
		      		$('#departmentAuth').iCheck('check');
		    		$('#peopleAuth').iCheck('uncheck');
	        	 }); 	
			}
    </script>
    
</body>
</html>

